package com.lagou;

import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.WritableComparable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;


//需求：1、升序 需要排序方法 2、bean对象做key 需要系列化方法

public class FileBean implements WritableComparable<FileBean> {

    private Integer id;  //编号
    private Integer value;  //数值

    public FileBean() {

    }

    public FileBean(Integer id, Integer value) {
        this.id = id;
        this.value = value;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Integer getValue() {
        return value;
    }

    public void setValue(Integer value) {
        this.value = value;
    }

    public int compareTo(FileBean o) {  //升序

        return this.value.compareTo(o.getValue());
    }

    public void write(DataOutput out) throws IOException {

        out.writeInt(id);
        out.writeInt(value);
        //writeint 和 write 有本质区别！！
//        writeint 写满int4位 write只写最低位

    }

    public void readFields(DataInput in) throws IOException {

        this.id = in.readInt();
        this.value=in.readInt();
    }

    //输出格式

    @Override
    public String toString() {
        return id+"\t"+value;
    }

}
